#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

constexpr bool debugMode=false;

long long maxConsecutiveSum(const std::vector<long long> &raw){
    std::vector<long long> state(raw.size());
    
    std::vector<std::pair<int,int>> record(raw.size());

    for(int i=0;i<=int(raw.size())-1;i++){
        // 初始 or 截断
        if(i-1<=-1 || state[i-1]<=-1){
            state[i]=raw[i];
            record[i]=std::make_pair(i,i);
        }
        else{
            state[i]=raw[i]+state[i-1];
            record[i]=std::make_pair(record[i-1].first,i);
        }
    }

    // 找最大值
    int maxpos=0;
    for(int i=0;i<=int(state.size())-1;i++){
        if(state[i]>state[maxpos]){
            maxpos=i;
        }
    }

    
    if(debugMode){
        std::cout<<record[maxpos].first<<'~'
        <<record[maxpos].second<<std::endl;
    }
    return state[maxpos];
}

int main(){
    // std::cout<<"good night"<<std::endl;
    // std::cout<<sizeof(long long int)<<' '<<sizeof(int)<<std::endl;

    // std::vector<long long> test={-3,4,9,-2,-5,8,-3};
    // std::cout<<maxConsecutiveSum(test)<<std::endl;
    int n;
    std::cin>>n;
    // std::cout<<"receive"<<n<<std::endl;
    std::vector<long long> raw(n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&raw[i-1]);
    }
    std::cout<<maxConsecutiveSum(raw);
    return 0;
}